from django.core.management.base import BaseCommand, CommandError

import os


class Command(BaseCommand):
    def handle(self, *args, **options):
        path = r"i:\zhangle\影视\电影"

        files = os.listdir(path)

        files_path = [os.path.join(path, f) for f in files if os.path.isfile(os.path.join(path, f))]

        dir_names = [os.path.splitext(f)[0] for f in files if os.path.isfile(os.path.join(path, f))]

        new_dir_paths = [os.path.join(path, name) for name in dir_names]

        for (f, new_dir) in zip(files_path, new_dir_paths):
            os.mkdir(new_dir)
            os.rename(f, os.path.join(new_dir, os.path.basename(f)))
            print("%s - %s" % (f, new_dir))
